package com.zhoux.api.io.raf;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.function.DoubleToIntFunction;

/**
 * @author taoyi
 * @version 1.0
 * @date 2021/3/25 14:20
 *
 *  本类用于测试读写基本数据类型, 以及RAF的指针操作
 *
 */
public class FAFDemo4 {
    public static void main(String[] args) {
        RandomAccessFile raf = null;

        try {
            raf = new RandomAccessFile(".\\src\\main\\java\\com\\zhoux\\file\\test.txt","rw");
            int i = Integer.MAX_VALUE;
            /**
             * raf.write(i>>>24);
             * raf.write(i>>>16);
             * raf.write(i>>>8);
             * raf.write(i>>>0);
             */
            raf.writeInt(i);
            raf.writeFloat(3.2f);
            raf.writeDouble(3.33);
            System.out.println("写入成功！");
            System.out.println(raf.getFilePointer());

            raf.seek(0);
            System.out.println(raf.getFilePointer());
            System.out.println(raf.readInt());
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                raf.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
